<?php
/**
 * Description of StaticWacFormStatus
 *   WacStatus references 
 *
 * @author ben
 */
class WacQualityCode
{
    public static $ok    = "ok";
    public static $nok   = "nok";

    public static $params = array(
          'ok'        => array('id'=>1, 'code'=>1, 'group'=>'1', 'name'=>"ok", 'caption'=>"合格"),
          'nok'       => array('id'=>2, 'code'=>2, 'group'=>'1', 'name'=>"nok", 'caption'=>"不合格"),
    );

    public static function getInstance()
    {
        $class = __CLASS__;
        if(is_null(self::$_instance)) {
            self::$_instance = new $class();
        }
        return self::$_instance;
    }

    public function __construct()			// construct method
    {
        ;
    }

    /*
     * get attribute
     */
    public static function getAttribute($key, $attribute)
    {
        return self::$params[$key][$attribute];
    }

    /*
     * getId
     */
    public static function getId($key)
    {
        return self::getAttribute($key, 'id');
    }

    /*
     * getCode
     */
    public static function getCode($key)
    {
        return self::getAttribute($key, 'code');
    }

    /*
     * getName
     */
    public static function getName($key)
    {
        return self::getAttribute($key, 'name');
    }

    /*
     * getCaption
     */
    public static function getCaption($key)
    {
        return self::getAttribute($key, 'caption');
    }

    /*
     * getCaption
     */
    public static function getCaptionById($id)
    {
        return self::getAttributeById($id, 'caption');
    }

    /*
     * @return caption
     */
    public static function getAttributeById($id, $attribute)
    {
        $row = self::getRowById($id);
        if($row != false){
            return $row[$attribute];
        }
    }

    /*
     *  getRowById
     * @return false or found array
     */
    public static function getRowById($id)
    {
        $result = false;
        foreach(self::$params as $param)
        {
            if($param['id']==$id)
            {
                $result = $param;
                break;
            }
        }
        return $result;
    }

}
